package com.zygh.interactiveplatform.module.controller;


import com.alibaba.fastjson.JSONObject;
import com.zygh.interactiveplatform.common.anno.PcLog;
import com.zygh.interactiveplatform.common.constant.SwaggerTagConst;
import com.zygh.interactiveplatform.common.domain.ResponseDTO;
import com.zygh.interactiveplatform.module.entity.Dept;
import com.zygh.interactiveplatform.module.service.DeptService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author lee
 * @since 2021-01-28
 */
@RestController
@RequestMapping("/dept")
@Api(tags = {SwaggerTagConst.Admin.MANAGER_DEPT})
public class DeptController {
    @Resource
    private DeptService deptService;

    @ApiOperation(value = "部门新增", notes = "部门新增")
    @PostMapping("addDept")
    @PcLog(logType = "2", module = SwaggerTagConst.Admin.MANAGER_DEPT, content = "部门新增")
    public ResponseDTO addDept(@RequestBody @Valid Dept dept) {
        return deptService.addDept(dept);
    }

    @ApiOperation(value = "部门修改", notes = "部门修改")
    @PostMapping("updateDept")
    @PcLog(logType = "3", module = SwaggerTagConst.Admin.MANAGER_DEPT, content = "部门修改")
    public ResponseDTO updateDept(@RequestBody @Valid Dept dept) {
        return deptService.updateDept(dept);
    }

    @ApiOperation(value = "删除部门", notes = "删除部门")
    @PostMapping("deleteDept")
    @PcLog(logType = "4", module = SwaggerTagConst.Admin.MANAGER_DEPT, content = "删除部门")
    public ResponseDTO deleteDept(@RequestBody String id) {
        String s = JSONObject.parseObject(id).get("id").toString();
        Integer new_id = Integer.parseInt(s);
        return deptService.deleteDept(new_id);
    }

    @ApiOperation(value = "查询所有部门", notes = "查询所有部门")
    @GetMapping("findDeptAll")
    @PcLog(logType = "1", module = SwaggerTagConst.Admin.MANAGER_DEPT, content = "查询所有部门")
    public ResponseDTO findDeptAll(Integer current, Integer size) {
        return deptService.findDeptAll(current,size);
    }

}
